//
//  ChildMianViewController.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/21.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "ChildMianViewController.h"
#import "HBHZhixunViewController.h"

#import "FindCell.h"
#import "NewsCell.h"
@interface ChildMianViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,strong)NSMutableArray *dataArr;;
@property (nonatomic,assign)NSInteger PageNumber;

@end

@implementation ChildMianViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _PageNumber = 1;
    _dataArr = [NSMutableArray new];
    [self.view addSubview:self.tableV];
    [self getDatas];
}

-(UITableView *)tableV
{
    if (!_tableV) {
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,44, SCREENW, SCREENH-44-64) style:UITableViewStyleGrouped];
        _tableV.backgroundColor = backColor;
        _tableV.estimatedRowHeight = 175*screenW_6;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        _tableV.delegate = self;
        _tableV.dataSource = self;
//        _tableV.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
//            _PageNumber = 1;
//            //            [self addOrderRequest:YES];
//        }];
//        _tableV.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
//            _PageNumber++;
//            //            [self addOrderRequest:NO];
//        }];
    }
    return _tableV;
}
#pragma Mark TableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5*screenW_6;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.000001;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsCell"];
    if (cell == nil) {
        cell = [[NewsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"NewsCell"];
    }
    //加载cell
    [cell setDataDic:_dataArr[indexPath.row]];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HBHZhixunViewController *vc = [HBHZhixunViewController new];
    vc.zhixunId = _dataArr[indexPath.row][@"id"];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)getDatas
{
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/information/list" Dic:@{@"type":_idStr?_idStr:@"",@"pageSize":@"10",@"pageNo":[NSString stringWithFormat:@"%ld",_PageNumber]} completion:^(NSDictionary *responseDic) {
            [HudHelper hideHudToView:self.view];
            if ([responseDic[@"success"] boolValue]) {
                [_dataArr addObjectsFromArray:responseDic[@"data"]];
                [_tableV reloadData];
            }else{
                [TomamaUI creatAlertWithTarget:self message:responseDic[@"msg"] timeInterval:2];
            }
        }];
    });
}

@end
